/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.List;
import webserviceclient.Transaction;

/**
 *
 * @author Jhovany Amaya
 */
public class CreateReport {

    public CreateReport() {
    }

    public boolean createReport(File fileToSave, List<Transaction> transactions) {
        boolean ret = true;
        FileWriter fileWriter = null;
        PrintWriter printWriter = null;
        try{
            fileWriter = new FileWriter(fileToSave);
            printWriter = new PrintWriter(fileWriter);
            for (Transaction t: transactions){
                printWriter.println("DNI cliente: " + t.getDNI());
                printWriter.println("Tipo de Doc.: " + t.getDocumentTipe());
                printWriter.println("Fecha: " + t.getDate());
                printWriter.println("Sucursal: " + t.getBranch());
                printWriter.println("Almacen: " + t.getStore());
                printWriter.println("Detalle compra: " + t.getPurchaseDetail());
                printWriter.println("Valor: " + t.getAmount());
                printWriter.println("Id archivo: " + t.getFile());
                printWriter.println("Fraquicia: " + t.getFranchise());
                printWriter.println("Motivo: " + t.getMotive());
                printWriter.println("Resultado validación: " + t.getValidationResult());
                printWriter.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
            ret = false;
        } finally {
           try {
               if (null != fileWriter)
                  fileWriter.close();
           } catch (Exception e2) {
              e2.printStackTrace();
              ret = false;
           }
        }
        
        return ret;
    }
    
}
